Xceed Grid for WinForms v4.3 Documentation
How to use gradient maps

Welcome to Xceed Grid for WinForms v4.3 > Basic Concepts > Appearance > How to use gradient maps

Xceed Grid for WinForms provides gradient maps. A GradientMap applies a series of colors to the part of the grid for which it is defined. The colors run along an axis and change gradually from one color to the next. By using gradient maps, you can create the illusion of light and shadow, and smooth surfaces. A GradientMap provides two ways of controlling its appearance. First, the GradientStops property contains a list of GradientStop objects, which provide properties for defining the colors (Color property) in the gradient and for indicating where the colors fall in the gradient (Offset property). Second, the GradientMode property represents the orientation of the grading, namely, vertical (the default) or horizontal.

Gradient maps can be used in two ways: either statically or dynamically. When used statically, the gradient map is always displayed and does not react to user interaction; it is defined in the GradientMap property of a VisualGridElement, GridControl or a MasterGrid. When used dynamically, however, the gradient map is used to indicate the state of the part of the grid to which it is applied and therefore is displayed only in certain conditions; it is defined using the HotVisualStyle (available for VisualGridElement and VisualGridElementStyle objects) property, or the SelectionVisualStyle, ErrorVisualStyle or InactiveSelectionVisualStyle properties (available for GridControl, DetailGrid, and GridStyle objects). See Using interactive visual styles for more details.

Using gradient maps

As stated elsewhere, a gradient map is described in terms of a list of gradient stops and a gradient mode. Each gradient stop has an offset (GradientStop.Offset) and a color (GradientStop.Color). The offset is a double value representing a position along an axis whose direction is determined by the gradient mode of the gradient map that contains the gradient stop. The offset can have a value between 0 and 1, with 0 representing a position at the beginning of the gradient, and 1 representing a position at the end of the gradient.

A gradient stop's offset can be thought of as a point along the gradient axis where its color will be pure; the color of points between two offsets will gradually change from the color of the first gradient stop to the color of the second gradient stop.

The following code illustrates how to apply a gradient to a grid control:

VB.NET Copy Code
gridControl1.GradientMap.GradientStops.Add(New GradientStop(0, Color.Red))
gridControl1.GradientMap.GradientStops.Add(New GradientStop(.5, Color.LightGreen))
gridControl1.GradientMap.GradientStops.Add(New GradientStop(1, Color.Blue))
C# Copy Code
gridControl1.GradientMap.GradientStops.Add(new GradientStop(0, Color.Red));
gridControl1.GradientMap.GradientStops.Add(new GradientStop(.5, Color.LightGreen));
gridControl1.GradientMap.GradientStops.Add(new GradientStop(1, Color.Blue));                   

The code snippet will result in a grid control (specifically, the area in which data is displayed) that starts off at the upper edge with a background color of red. This color gradually changes to light green being displayed as a pure color half-way down the grid, or at the .5 position. Finally, the color changes to blue at the lower edge.

The offset value passed to the GradientStop constructor must be between 0 and 1; otherwise, an exception will be thrown. Furthermore, each gradient stop added to a given gradient map must be greater than the previously added gradient stop, or an exception will be thrown. To avoid this, call the ResetGradientMap method.

Transparency is also supported, so you can use alpha values. In the following code, a value of 50 is passed as an alpha value, causing the color (red in this case) to be transparent: 

VB.NET Copy Code
gridControl1.GradientMap.GradientStops.Add(New GradientStop(0, _
                                           Color.FromArgb((CInt(Fix((CByte(50))))), _ 
                                           (CInt(Fix((CByte(255))))), (CInt(Fix((CByte(0))))), _
                                           (CInt(Fix((CByte(0))))))))               
C# Copy Code
gridControl1.GradientMap.GradientStops.Add(new GradientStop(0, Color.FromArgb(((int)(((byte)(50)))),
                                           ((int)(((byte)(255)))), ((int)(((byte)(0)))),
                                           ((int)(((byte)(0)))))));

Finally, by default, the orientation of the gradient axis is vertical. The orientation can be changed to horizontal by setting the gradient map's GradientMode to Horizontal: 

VB.NET Copy Code
gridControl1.GradientMap.GradientMode = Xceed.UI.GradientMode.Horizontal               
C# Copy Code
gridControl1.GradientMap.GradientMode = Xceed.UI.GradientMode.Horizontal;                   

Gradient maps can also be fully configured in the designer through the GradientMap property in the Property window and the Gradient Stop Editor.

Three stylesheets that take advantage of the gradient map feature are provided with Xceed Grid for WinForms: Vista-like, Office 2007 blue, and Office 2007 silver.